<template>
  <tl-sub-page :render="render" :visible.sync="dialogVisible" v-dialogDrag :title="'过程分析'" :close-on-click-modal="false" class="tl-dialog" :fullscreen="true" append-to-body @close="close">
    <!--表格渲染-->
    <el-table class="tl-table" ref="mainTable" :height="elTableHeight" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-click="doRowClick" @row-dblclick="doRowDbClick"  row-key="id" border fit :row-class-name="doChangeRowClassName">
      <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
      <el-table-column prop="milepostname" label="里程碑及任务名称" width="200px" sortable="custom" sort-by="milepostname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="planfinishtime" label="计划达成日期" width="140px" sortable="custom" sort-by="planfinishtime" align="center" header-align="center" :show-overflow-tooltip="true" :formatter="dateFormat"></el-table-column>
      <el-table-column prop="actualfinishtime" label="实际完成日期" width="140px" sortable="custom" sort-by="actualfinishtime" align="center" header-align="center" :show-overflow-tooltip="true" :formatter="dateFormat"></el-table-column>
      <el-table-column prop="deliverable" label="交付成果" min-width="350px" sortable="custom" sort-by="deliverable" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="completionstatus" label="完成情况" width="350px" sortable="custom" sort-by="completionstatus" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="differenceanalysis" label="差异分析" width="350px" sortable="custom" sort-by="differenceanalysis" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="操作" width="80px" v-slot="scope" fixed="right">
        <el-button icon="el-icon-edit" type="text" @click.native.stop="openEditDialog('editForm', scope.row.id)" :disabled="disabled">编辑</el-button>
      </el-table-column>
    </el-table>
    <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './editComp'
import { validateNull } from '@tapui/utils/validate'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
import { checkPermission } from '@tapui/utils/permission'
export default {
  name: 'mpmProjectMilepost',
  mixins: [mixin_list],
  components: { tlEdit },
  data() {
    return {
      description: '项目策划-里程碑及任务-列表查询',
      urlPrefix: '/mpm/projectMilepost/',
      url: {
        // queryCodeList: '/mpm/projectMilepost/dataCodeList'
        list: '/mpm/projectMilepost/list',
        load: '/mpm/projectMilepost/load'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'planfinishtime',
        sord: 'asc'
      },
      pageInfo: {
        currentPage: 1, // 当前页面
        pageSize: 1000, // 每页记录数
        pageSizes: ['10', '50', '100'],
        totalCount: 0 // 总数
      },
      isQueryOnCreated: false,
      datas: [],
      dialogVisible: false,
      clickTimer: null
    }
  },
  props: {
    model: {
      default: function() {
        return {}
      },
      type: Object
    },
    render: {
      default: 'div',
      type: String
    },
    elTableHeight: {
      default: 200
    },
    disabled: {
      default: false
    }
  },
  methods: {
    doRowClick(row, column, event) {
      // this.$refs.mainTable.toggleRowSelection(row)
      if (row[this.$refs.mainTable.rowKey] !== this.clickRowkey) {
        this.clickRowkey = row[this.$refs.mainTable.rowKey]
      } else {
        this.clickRowkey = ''
      }
      // 解决双击调用点击事件防范问题
      clearTimeout(this.clickTimer)
      this.clickTimer = setTimeout(() => {
        this.$emit("fullScreen")
      }, 300)
    },
    doRowDbClick(row, column, event) {
      // 解决双击调用点击事件防范问题
      clearTimeout(this.clickTimer)
      if (this.rowDbClickActionType === 'edit') {
        // 判断是否有权限
        if (this.editPermission.length > 0) {
          if (checkPermission(this.editPermission)) {
            this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
          } else {
            this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
          }
        } else {
          this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
        }
      } else if (this.rowDbClickActionType === 'view') {
        this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
      }
    },
    beforeLoadData() {
      if (!this.model.projectcode) {
        return false
      }
      this.queryParam.qry_projectcode = this.model.projectcode
      this.queryParam.qry_planapprovalstate = '9'
      this.queryParam.qry_enabled = '1'
      return true
    },
    open() {
      this.dialogVisible = true
      this.$nextTick(() => {
        this.doQuery()
      })
    },
    afterLoadData() {
      this.$refs.mainTable.doLayout()
    },
    close() {
      this.$emit('refresh')
    },
    openEditDialog(editForm, id) {
      if (!this.beforeOpenEditDialog(editForm, id)) {
        return
      }
      this.$refs[editForm].id = id
      this.$refs[editForm].isAdd = false
      this.$refs[editForm].visible = true
      if (this.disabled) {
        this.$refs[editForm].disableEditSubmit = true
      } else {
        this.$refs[editForm].disableEditSubmit = false
      }
      this.$nextTick(() => {
        this.afterOpenEditDialog(editForm, id)
      })
      let that = this
      setTimeout(() => {
        that.clickRowkey = id
      }, 100)
    }
  }
}
</script>
<style scoped></style>

